<?php


namespace app\admin\command;

use app\admin\model\Store;
use app\admin\model\user\Card;
use app\admin\model\Reserve;
use app\admin\model\Room;
use app\common\library\Yunding;
use Carbon\Carbon;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Db;
use think\Env;
use think\Exception;
use think\Log;

class TransDzmtCode extends Command
{

    protected function configure()
    {
        $this->setName('trans_dzmt_code')
            ->setDescription('把大众美团的code放到一个独立的字段');
    }

    protected function execute(Input $input, Output $output)
    {
        @ini_set("memory_limit", '-1');
        $stime = microtime(true);

        $recodes = Card::where('pay_way', 1)->select();

        $count = 0;
        foreach ($recodes as $item) {
            if (!empty($item->dzmt)) {
                try {
                    $kk = unserialize($item->dzmt);
                } catch (Exception $e) {
                    continue;
                }
                $item->dzmt_code = $kk[0]['receipt_code'];
                $item->save();
                $count++;
                echo $count . PHP_EOL;
            }
        }

        echo $count . PHP_EOL;

        $etime = microtime(true);//获取程序执行结束的时间
        $total = $etime - $stime;   //计算差值
        $output->writeln($total);
    }

}
